package zeebe.human;

import io.vertx.core.json.JsonObject;
import io.zeebe.client.ZeebeClient;
import io.zeebe.client.api.response.ActivatedJob;
import io.zeebe.client.api.worker.JobClient;
import io.zeebe.client.api.worker.JobHandler;

public class HumanJobWorkerHandler implements JobHandler {
    ZeebeClient zeebeClient;

    public HumanJobWorkerHandler(ZeebeClient client) {
        this.zeebeClient = client;
    }

    @Override
    public void handle(JobClient client, ActivatedJob job) throws Exception {
        System.out.println("开始执行humanJobWorker");

        JsonObject data = new JsonObject(job.getVariables());
        int a = data.getInteger("a");
        int b = data.getInteger("b");

        int c = a + b;
        JsonObject output = new JsonObject()
                .put("c", c);

        client.newCompleteCommand(job.getKey())
                .variables(output.encode())
                .send()
                .join();
    }
}
